<template>
  <div class="container">
    <!-- tool start -->
    <el-form :model="formInline" label-width="120px" @keyup.enter.native="search">
      <el-row>
        <el-col :span="8">
          <el-form-item label="类型名称：">
            <el-input maxlength="20" show-word-limit v-model="formInline.locationtypename"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="状态：">
            <el-select v-model="formInline.state">
              <el-option
                v-for="(item,index) in stateOptions"
                :key="index"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="24" align="right">
          <el-button type="primary" @click="search">{{$t('m.query')}}</el-button>
          <el-button type="primary" @click="handleLocationType()">{{$t('m.add')}}</el-button>
          <el-button type="primary" @click="modefyState">修改状态</el-button>
        </el-col>
      </el-row>
    </el-form>
    <!-- tool end -->

    <!-- table数据展示 start -->
    <el-row class="table-wrap">
      <el-col :span="24">
        <el-table
          ref="table"
          stripe
          empty-text
          fit
          :data="tableData"
          :row-style="tableRowStyle"
          :row-class-name="tableRowClassName"
          @row-click="rowClick"
          @selection-change="handleMultiSelectionChange">
          <el-table-column align="center" type="selection" width="55"></el-table-column>
          <el-table-column align="center" type="index" :label="$t('m.index')" width="50"></el-table-column>
          <el-table-column align="center" prop="name" label="类型名称"></el-table-column>
          <el-table-column align="center" label="状态">
            <template slot-scope="scope">{{scope.row.state|stateFilter}}</template>
          </el-table-column>
          <el-table-column align="center" label="长">
            <template slot-scope="scope">{{(scope.row.extent)+'cm'}}</template>
          </el-table-column>
          <el-table-column align="center" label="宽">
            <template slot-scope="scope">{{(scope.row.width)+'cm'}}</template>
          </el-table-column>
          <el-table-column align="center" label="高">
            <template slot-scope="scope">{{(scope.row.height)+'cm'}}</template>
          </el-table-column>
          <el-table-column align="center" prop="associationType" label="关联容器类型"></el-table-column>
          <el-table-column align="center" prop="remark" label="备注"></el-table-column>
          <el-table-column align="center" prop="creator" label="创建人"></el-table-column>
          <el-table-column align="center" prop="createdate" label="创建时间">
            <template slot-scope="scope">{{scope.row.createdate|dateFilter}}</template>
          </el-table-column>
          <el-table-column align="center" :label="$t('m.operation')">
            <template slot-scope="scope">
              <el-button type="text" @click.stop="handleLocationType(scope.row.id)">{{$t('m.edit')}}</el-button>
              <el-button type="text" style="color:#f56c6c" @click.stop="handleDelete(scope.row.id)">{{$t('m.delete')}}</el-button>
            </template>
          </el-table-column>
        </el-table>

        <el-pagination
          background
          layout="sizes, prev, pager, next, jumper"
          :page-sizes="pageSizeList"
          :page-size="rowSize"
          :current-page="page"
          :total="totalRows"
          @current-change="currentChange"
          @size-change="handleSizeChange">
        </el-pagination>
      </el-col>
    </el-row>
    <!-- table数据展示 end -->

    <!-- 新增 or 编辑 库位类型 start -->
    <handleLocationTypePopup
      v-if="handleLocationTypePopupVisible"
      :dialogVisible="handleLocationTypePopupVisible"
      :detail="locationTypeDetail"
      @close="handleLocationTypePopupVisible=false"
      @save="locationTypeSave">
    </handleLocationTypePopup>
    <!-- 新增 or 编辑 库位类型 end -->
  </div>
</template>
<script>
let __this
export default {
  name:'locationTypeSetting',
  data(){
    return {
      formInline:{
        locationtypename:'', // 库位类型名称
        state:'' // 库位类型状态
      },
      stateOptions:[ // 库位状态
        {label:'停用', value:0},
        {label:'启用', value:1}
      ],
      handleLocationTypePopupVisible:false, // 控制[新增 or 编辑]库位类型dialog显示隐藏
      locationTypeDetail:'',
      tableData:[]
    }
  },
  beforeCreate(){
    __this = this
  },
  mounted(){
    this.getData()
  },
  components:{
    handleLocationTypePopup:()=>import('@/components/locationTypeSetting/handle-location-type-popup') // 新增 or 编辑 库位类型组件
  },
  filters:{
    stateFilter(value){
      return  __this.stateOptions.find((item)=>{
        return item.value === value
      }).label
    }
  },
  methods:{
    search(){
      this.page = 1
      this.getData()
    },
    getData(){
      let options = {
        method:'get',
        url:`/locationtype/page`,
        params:Object.assign({}, this.formInline, {page:this.page,rows:this.rowSize})
      }
      this.$axios(options).then(({ data }) => {
        this.tableData = data.records
        this.totalRows = data.total
        this.page = data.current
        if (!this.tableData.length)
          return this.callbackMessage(this.$t('m.nodata'))
      })
    },
    // 新增 or 编辑 组件
    handleLocationType(id){
      if(id){ // 编辑

      } else { // 新增
        this.locationTypeDetail = ''
        this.handleLocationTypePopupVisible = true
      }
    },
    // 修改状态
    modefyState(){
      if(!this.tableRowSelected.length) return this.callbackMessage('请选择库位类型')

    },
    // 表格-删除
    handleDelete(id){
      this.$confirm('是否删除?', '提示', {
        confirmButtonText:'确定',
        cancelButtonText:'取消',
        type:'warning'
      }).then(() => {

      }).catch(() => {
        this.callbackMessage('已取消删除','info')
      })
    },
    // 保存新增or编辑的数据
    locationTypeSave(formData){

    }
  }
}
</script>
<style lang="scss" scoped>
.el-select{width: 100%;}
</style>